using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Calendar.UI
{
    public partial class frmAlertController : Form
    {
        CalendarBLL bll = new CalendarBLL();
        public static frmAlertBehindSchedule fabs;
        public static frmAlertMilestoneConflict famc;
        public static frmAlertBudgetOverConsumed faboc;

        public frmAlertController()
        {
            InitializeComponent();
        }

        private void frmAlertController_Load(object sender, EventArgs e)
        {
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.WindowState = FormWindowState.Minimized;
            timer1.Enabled = true;
            //timer1.Interval = 10 * 1000; // 1000 mean 1 second
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //timer1.Interval = 10 * 1000; // 1000 mean 1 second
            if (GlobalInfo.UserId.Equals("") == false) // user is logged in
            {
                DataTable dt;
                //dt = bll.getMilestonesWithBudgetOverConsumed(); // for testing only

                dt = bll.getDelayedTasks();
                if ((dt.Rows.Count > 0) && (fabs == null) && (famc == null) && (GlobalInfo.AlertFabsShownOnce == false))
                {
                    fabs = new frmAlertBehindSchedule(dt);
                    fabs.Show();
                    //timer1.Enabled = false;
                }

                dt = bll.getConflictingMilestones();
                if ((dt.Rows.Count > 0) && (famc == null) && (fabs == null) && (GlobalInfo.AlertFamcShownOnce == false))
                {
                    famc = new frmAlertMilestoneConflict(dt);
                    famc.Show();
                    //timer1.Enabled = false;
                }

                dt = bll.getMilestonesWithBudgetOverConsumed();
                if ((dt.Rows.Count > 0) && (famc == null) && (fabs == null) && (faboc == null) && (GlobalInfo.AlertFbocShownOnce == false))
                {
                    faboc = new frmAlertBudgetOverConsumed(dt);
                    faboc.Show();
                    //timer1.Enabled = false;
                }
            }

            timer1.Interval = 7 * 1000; // 1000 mean 1 second
        }
    }
}